package org.springcloud.wisdom.spring_01_canteen.login.service;

import org.springcloud.wisdom.spring_01_canteen.login.dao.Clogindao;
import org.springcloud.wisdom.spring_01_canteen.login.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Cloginservice2 {
    @Autowired
    private Clogindao clogindao;

    public Object login(LoginRequest loginRequest) {
        String username = loginRequest.getUsername();
        String password = loginRequest.getPassword();

        // 检查学生
        Student student = clogindao.login(username, password);
        if (student != null) {
            return student;
        }

        // 检查商家
        Mall mall = clogindao.login1(username, password);
        if (mall != null) {
            return mall;
        }

        // 检查管理员
        Admin admin = clogindao.login2(username, password);
        if (admin != null) {
            return admin;
        }

        //检查老师
        Teacher teacher = clogindao.login3(username, password);
        if (teacher != null) {
            return teacher;
        }

        //检查新生
        Freshman freshman = clogindao.login4(username, password);
        if (freshman != null) {
            return freshman;
        }

        //如果都不是
        return null;
    }
}
